//
//  LWLoopCell.m
//  轮播器封装
//
//  Created by Alphts on 16/7/10.
//  Copyright © 2016年 Alphts. All rights reserved.
//

#import "LWLoopCell.h"
#import "UIImageView+WebCache.h"
#define kLoopCellSize self.contentView.frame.size

@interface LWLoopCell ()



@property (nonatomic, weak) UILabel *lb_title;

@property (nonatomic, weak) UIPageControl *pageControl;


@end

@implementation LWLoopCell

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}


- (void)setupUI{
    
    self.contentView.backgroundColor = [UIColor colorWithRed:arc4random_uniform(255)/256.0 green:arc4random_uniform(255)/256.0 blue:arc4random_uniform(255)/256.0 alpha:1.0];
    
    UIImageView *iv_photo = [[UIImageView alloc] init];
    
    self.iv_photo = iv_photo;
    
    iv_photo.frame = self.contentView.frame;
    [self.contentView addSubview:iv_photo];
    

    
    UILabel *lb_title = [[UILabel alloc] init];
    self.lb_title = lb_title;
    [self.lb_title setTextColor:[UIColor blackColor]];
    [self.contentView addSubview:lb_title];
    
    UIPageControl *pageControl = [[UIPageControl alloc] init];
    self.pageControl = pageControl;
    [self.contentView addSubview:pageControl];
    
    
    
}

#pragma mark - 重写属性的setter方法
- (void)setStyle:(kLoopStyle)style{
    _style = style;
    
    if (style == kLoopStylePage) {
        self.pageControl.frame = CGRectMake(0, kLoopCellSize.height-31, kLoopCellSize.width, 21);
    }else if (style == kLoopStylePageAndTitle){
        
        self.lb_title.frame = CGRectMake(20, kLoopCellSize.height-31, kLoopCellSize.width*2/3, 21);
        
        self.pageControl.frame = CGRectMake(CGRectGetMaxX(self.lb_title.frame), self.lb_title.frame.origin.y, kLoopCellSize.width - CGRectGetMaxX(self.lb_title.frame), self.lb_title.frame.size.height);
    }
    
    
    
}


- (void)setTitle:(NSString *)title{
    _title = title;
    self.lb_title.text = title;
}

- (void)setTitleFont:(CGFloat)titleFont{
    _titleFont = titleFont;
    self.lb_title.font = [UIFont systemFontOfSize:titleFont];
}

- (void)setTitleColor:(UIColor *)titleColor{
    _titleColor = titleColor;
    self.lb_title.textColor = titleColor;
}

- (void)setTotalCount:(NSInteger)totalCount{
    _totalCount = totalCount;
    self.pageControl.numberOfPages = totalCount;
}

- (void)setCurrentCount:(NSInteger)currentCount{
    _currentCount = currentCount;
    self.pageControl.currentPage = currentCount;
}

- (void)setCurrentPageColor:(UIColor *)currentPageColor{
    _currentPageColor = currentPageColor;
    self.pageControl.currentPageIndicatorTintColor = currentPageColor;
}

- (void)setPageColor:(UIColor *)pageColor{
    _pageColor = pageColor;
    self.pageControl.pageIndicatorTintColor = pageColor;
}

@end




